package com.force.abril.prevision.download.transformer;


import static com.force.abril.prevision.download.transformer.PrevisionFieldMapping.FIELDS;

import java.lang.reflect.InvocationTargetException;
import java.util.List;

import org.apache.commons.beanutils.BeanUtilsBean2;

import br.com.abril.prevision.Prevision;

import com.force.abril.transformer.Mapping;
import com.sforce.soap.partner.sobject.SObject;

public class TranformerHelper {


	public Prevision toLocalPrevision(SObject salesForceRow) {

		Prevision prevision = new Prevision();
		
		prevision.setWallet( salesForceRow.getField("AgenciaMigrada__c").toString() +
							 salesForceRow.getField("AnuncianteMigrado__c").toString() +
				             salesForceRow.getField("ProdutoAbril__c").toString() );
		
		for (Mapping mapping : FIELDS) {
			
			try {
			
				BeanUtilsBean2.getInstance().setProperty(prevision, mapping.getKey() , salesForceRow.getField( mapping.getValue()) );
			
			} catch (IllegalAccessException e) {
				e.printStackTrace();
			
			} catch (InvocationTargetException e) {
				e.printStackTrace();
			}
			
		}
		
		return prevision;
		
	}

	
	
}
